#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node {
	int p, a;
} a[5005];

signed main() {
	int m, n;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i].p >> a[i].a;
	}

	sort(a + 1, a + m + 1, [](node x, node y) {
		return x.p < y.p;
	});

	int ans = 0;
	for (int i = 1; n && i <= m; i++) {
		if (a[i].a <= n) {
			ans += a[i].p * a[i].a;
			n -= a[i].a;
		} else {
			ans += a[i].p * n;
			n = 0;
		}
	}
	cout << ans;
	return 0;
}
